//# sourceURL=http://uMapApp/UI/Panel/PositionPopPanel
define([
    "mhjs/mhjs",
    "uMap/uMap",
    "./FloatPanel"
], function (
    mhjs,
    uMap,
    FloatPanel
) {

    function PositionPopPanel(option) {

        var _this = this;

        //内置对象
        _this.ui = _this.ui || {};
        _this.ui.arrow = new mhjs.Div({"class": "arrow"});


        //类继承，参数赋值
        FloatPanel.call(_this, option);
        _this.addClass("floatPanel positionPopPanel");
        _this.append(_this.ui.arrow);

        _this.bottomPadding = 50;

        _this.topLimit = 500;

        //设定跟随监听对象
        _this.positionListener = new uMap.ScreenPositionListener({
            earth   : _this.earth,
            listener: function (screenPosition) {

                // var halfWidth = _this.earth.canvas.width / 2;
                // var halfHeight = _this.earth.canvas.height / 2;
                //
                // var direction = 1;
                // var offset = _this.bottomPadding;
                //
                // if (screenPosition.x < halfWidth && screenPosition.y < halfHeight) {
                //
                //
                //
                //
                // } else if (screenPosition.x < halfWidth && screenPosition.y > halfHeight) {
                //
                // } else if (screenPosition.x < halfWidth && screenPosition.y > halfHeight) {
                //
                // } else {
                //
                // }

                if (screenPosition.y < _this.topLimit) {

                    _this.css({
                        left: screenPosition.x,
                        top : screenPosition.y + _this.bottomPadding
                    });

                    _this.addClass("down");

                } else {
                    _this.css({
                        left: screenPosition.x,
                        top : screenPosition.y - _this.bottomPadding
                    });

                    _this.removeClass("down");
                }


            }
        });

        _this.on("open", function () {
            _this.positionListener.start();
        });

        _this.on("close", function () {
            _this.positionListener.stop();
        });

    }

    var _class = PositionPopPanel;
    mhjs.Inherit(_class, FloatPanel);

    Object.defineProperties(_class.prototype, {
        "position": {
            get: function () {
                var _this = this;
                return _this.position;
            },
            set: function (position) {
                var _this = this;
                _this._position = position;
                _this.positionListener.position = position;
            }
        },
        "clear"   : {
            value: function () {
                var _this = this;
                _this.content && _this.content.detach();
            }
        },
        "content" : {
            get: function () {
                var _this = this;
                return _this._content;
            },
            set: function (content) {
                var _this = this;
                _this.clear();
                _this._content = content;
                _this.append(content);
            }
        }
    });

    return _class;

});